<?php
/**
 * 服务池
 */
namespace Core\Lib;
class ServicePool {
    /**
     * 对象池
     * @var array 
     */
    private static $_services = [];
    
    /**
     * 添加对象
     * @param \Services\Service $service
     * @return \Services\Service|boolean
     */
    public static function pushService($service){
        $service_id = $service->getServiceId();
        if(!$service_id){
            return false;
        }
        return self::$_services[$service_id] = $service;
    }
    
    /**
     * 获取服务对象
     * @param string        服务对象ID
     * @return \Services\Service|false
     */
    public static function getService($service_id){
        return isset(self::$_services[$service_id]) ? self::$_services[$service_id] : false;
    }
    
    /**
     * 移除服务对象
     * @param string        服务对象ID
     */
    public static function removeService($service_id){
        if(array_key_exists($service_id, self::$_services)){
            unset(self::$_services[$service_id]);
        }
        return true;
    }
    
    /**
     * 清空对象池
     * @return boolean
     */
    public static function cleanPool(){
        self::$_services = [];
        return true;
    }
}